package com.lcf.system.controller;


import com.lcf.framework.vo.PageVO;
import com.lcf.system.dto.ArticleDTO;
import com.lcf.system.query.ArticlePageQuery;
import com.lcf.system.service.ArticleService;
import com.lcf.system.vo.ArticleVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 文章(Article)表控制层
 *
 * @author lcf
 * @since 2025-04-24 21:14:33
 */
@Tag(name = "文章")
@RestController
@RequestMapping("article")
public class ArticleController {
    @Resource
    private ArticleService articleService;

    /**
     * 新建
     */
    @Operation(summary = "新建")
    @PostMapping
    public boolean insert(@RequestBody @Validated ArticleDTO dto) {
        return articleService.insert(dto);
    }

    /**
     * 修改
     */
    @Operation(summary = "修改")
    @PostMapping("{id}")
    public boolean update(@PathVariable @Schema(description = "文章id") long id,
                          @RequestBody @Validated ArticleDTO dto) {
        return articleService.update(id, dto);
    }

    /**
     * 删除
     */
    @Operation(summary = "删除")
    @DeleteMapping("{id}")
    public boolean delete(@PathVariable @Schema(description = "文章id") long id) {
        return articleService.delete(id);
    }

    /**
     * 查询
     */
    @Operation(summary = "查询")
    @GetMapping("{id}")
    public ArticleVO query(@PathVariable @Schema(description = "文章id") long id) {
        return articleService.query(id);
    }

    /**
     * 分页查询
     */
    @Operation(summary = "分页查询")
    @GetMapping("page")
    public PageVO<ArticleVO> queryPage(ArticlePageQuery query) {
        return articleService.queryPage(query);
    }
}

